package com.toutoushidao.ssm.web;

import com.alibaba.fastjson.JSONArray;
import com.toutoushidao.ssm.service.OngService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/ong")
public class UserController {

    @Autowired
    private OngService ongService;

    private final Logger LOG = LoggerFactory.getLogger(this.getClass());

    @RequestMapping(
            value = "/userInfo",
//            method = RequestMethod.POST,
            produces = {"text/html;charset=UTF-8"})
    public ModelAndView userInfo(Model model) {
        // 获取用户列表
        JSONArray userList = ongService.userInfo();
        model.addAttribute("userList", userList);
        ModelAndView mv = new ModelAndView("userInfo");
        mv.addObject(userList);
        return mv;
    }

    @RequestMapping(
            value = "/tradeInfo",
//            method = RequestMethod.POST,
            produces = {"text/html;charset=UTF-8"})
    public ModelAndView tradeInfo(Model model) {
        // 获取交易列表
        JSONArray tradeList = ongService.tradeInfo();
        model.addAttribute("tradeList", tradeList);
        ModelAndView mv = new ModelAndView("tradeInfo");
        mv.addObject(tradeList);
        return mv;
    }
}
